
package com.admissions.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.admissions.R;
import com.admissions.model.DeThi;

/**
 * @author Bkav-DangNVb
 *
 */
public class SectionsAdapter extends BaseAdapter {

    private ArrayList<DeThi> mDeThis;

    private LayoutInflater mInflater;

    private Bitmap icon;

    public SectionsAdapter(Context context, ArrayList<DeThi> dethis) {
        this.mDeThis = dethis;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void setIcon(Bitmap icon) {
        this.icon = icon;
    }

    @Override
    public int getCount() {
        return mDeThis.size();
    }

    @Override
    public Object getItem(int position) {
        return mDeThis.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_layout, parent, false);
        }

        ImageView itemIcon = (ImageView) convertView.findViewById(R.id.item_icon);
        TextView itemName = (TextView) convertView.findViewById(R.id.item_name);
        TextView itemCaption = (TextView) convertView.findViewById(R.id.item_description);

        DeThi dethi = mDeThis.get(position);
        itemIcon.setImageBitmap(icon);
        itemName.setText(dethi.name);
        itemCaption.setText(dethi.description);

        convertView.setTag(dethi);
        return convertView;
    }

}
